package cn.exrick.xboot.quartz.jobs;

import cn.exrick.xboot.modules.masterdata.server.MasterDataUpdate;
import cn.exrick.xboot.quartz.jobs.distributedLock.entity.Lock;
import cn.exrick.xboot.quartz.jobs.distributedLock.utils.DistributedLockHandler;
import cn.hutool.core.date.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.dom4j.*;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;

import java.util.*;

@Slf4j
@DisallowConcurrentExecution
public class MasterDataJob implements Job {
    @Autowired
    private MasterDataUpdate masterDataUpdate;

    @Autowired
    private StringRedisTemplate template;

    @Autowired
    private DistributedLockHandler distributedLockHandler;

    @Override
    public void  execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        Lock lock=new Lock("masterlock","lockvalue");
        if(distributedLockHandler.tryLock(lock)) {
            try {
                synchronized ("") {
                    log.info(String.format("主数据的增量更新,时间: " + DateUtil.now()));
                    masterDataUpdate.dataUpdate();
                }
                distributedLockHandler.releaseLock(lock);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }

}
